import { type UserModule } from '@/types';
import { createHead, useHead } from 'unhead';

export const install: UserModule = ({ microEnv }) => {
  createHead();
  useHead({
    bodyAttrs: {
      'data-theme': microEnv?.theme ?? 'auto',
    },
  });

  if (window.__POWERED_BY_WUJIE__) {
    window.$wujie.bus.$on('theme', (theme: string) => {
      useHead({
        bodyAttrs: {
          'data-theme': theme,
        },
      });
    });
  }
};
